from pydantic import BaseModel, Field
from typing import Optional, Any

class ResponseSchema(BaseModel):
    code: int = Field(default=0, description="响应码")  # 响应码
    msg: str = Field(default="success", description="响应信息")  # 响应信息
    data: Optional[Any] = Field(None, description="响应数据")  # 响应数据，使用 Optional 表示可以为空

def success(data: Optional[Any] = None):
    """统一成功返回"""
    return {"code": 0, "msg": "success", "data": data}

def fail(msg: str = "fail", code: int = 400):
    """统一失败返回"""
    return {"code": code, "msg": msg, "data": None}